<template>
    <div>
        <el-row>
            <el-col :span="24">
                <h1>影评回复管理</h1>
            </el-col>
        </el-row>
        <el-row v-if="!updateShow">
            <el-col>
                <el-button @click="handleList">刷新</el-button>
            </el-col>
            <el-col>
                <el-input placeholder="请输入相关信息查询" v-model="input" class="input-with-select">
                    <el-button slot="append" icon="el-icon-search" @click="handlePage"></el-button>
                </el-input>
            </el-col>
            <el-col :span="24">
                <el-table
                        :data="tableData"
                        style="width: 100%"
                        @sort-change="sortTable">
                    <el-table-column
                            type="selection"
                            width="55">
                    </el-table-column>
                    <el-table-column
                            prop="id"
                            label="回复id"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="commentsId"
                            label="影评id"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="username"
                            label="影评人"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="reply"
                            label="回复内容"
                            width="180">
                    </el-table-column>

                    <el-table-column
                            prop="replyTime"
                            label="回复时间"
                            width="180">
                    </el-table-column>
                    <el-table-column  label="操作">
                        <template slot-scope="scope">
<!--                            <el-button size="mini" @click="handleShowMore(scope.$index)">显示更多</el-button>-->
                            <el-popconfirm
                                    confirm-button-text='好的'
                                    cancel-button-text='不用了'
                                    icon="el-icon-info"
                                    icon-color="red"
                                    title="这是一段内容确定删除吗？"
                                    @confirm="handleDelete(scope.$index)"
                            >
                                <el-button slot="reference" size="mini">删除</el-button>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
        </el-row>

        <!--        <el-form v-if="updateShow" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">-->
        <!--            <el-form-item label="品牌名" prop="brandTypeName">-->
        <!--                <el-input v-model="ruleForm.brandName"></el-input>-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="排序" prop="sort">-->
        <!--                <el-input v-model="ruleForm.sort"></el-input>-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="类型描述" prop="describe">-->
        <!--                <el-input v-model="ruleForm.introduce"></el-input>-->
        <!--            </el-form-item>-->
        <!--            <el-form-item>-->
        <!--                <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>-->
        <!--                <el-button @click="resetForm('ruleForm')">重置</el-button>-->
        <!--                <el-button @click="handleInsert">返回</el-button>-->
        <!--            </el-form-item>-->
        <!--        </el-form>-->
    </div>
</template>

<script>
    export default {

        name: "ReplyView.Vue",
        data() {
            return {
                tableData: [],
                tableDateCopy: [],
                actor: {},
                updateShow: false,
                input: '',
                ruleForm: {
                    replyId: '',
                    commentsId: '',
                    userName: '',
                    reply:'',
                    replyTime:'',

                },
                rules: {
                    replyId: [
                        { required: true, message: '回复id', trigger: 'blur' },
                    ],
                    commentsId: [
                        { required: true, message: '影评id', trigger: 'blur' }
                    ],
                    userName: [
                        { required: true, message: '影评人', trigger: 'blur' },
                    ],

                    reply: [
                        { required: true, message: '回复', trigger: 'blur' }
                    ],
                    replyTime: [
                        { required: true, message: '回复时间', trigger: 'blur' }
                    ]
                },
            }
        },
        created() {
            this.handleList();
        },
        methods:{
            handleList(){
                this.axios.get("manage/reply/list",{params:{commentsId:this.$route.query.comments}}).then(response=> {
                    if (response.data.code == 200) {
                        this.tableData = response.data.data.list;
                        this.tableDateCopy=[...this.tableData]
                    }
                })
            },
            // handleUpdate(index){
            //     const data=this.tableData[index];
            //     this.ruleForm=data;
            //     this.updateShow=!this.updateShow;
            // },
            // handleInsert(index){
            //     this.ruleForm={};
            //     this.updateShow=!this.updateShow;
            // },
            handleDelete(index){
                this.axios.get("manage/reply/delete",{params:{id:this.tableData[index].id}}).then(response=>{
                    if (response.data.code==200){
                        this.tableData.splice(index,1);
                    }
                })
            },
            // handleShowMore(index){
            //     this.axios.get("manage/reply/list").then(response=>{
            //         if (response.data.code == 200) {
            //             this.tableData = response.data.data.list;
            //             this.tableDateCopy=[...this.tableData]
            //         }
            //     })
            // },
            // submitForm(formName) {
            //     this.$refs[formName].validate((valid) => {
            //         if (valid) {
            //             this.axios.post("manage/brandType/saveOrUpdate",this.ruleForm,{params:{}}).then(response=>{
            //                 this.updateShow=false;
            //                 this.ruleForm={};
            //             })
            //         } else {
            //             console.log('错误填写');
            //             return false;
            //         }
            //     });
            // },
            // resetForm(formName) {
            //     this.$refs[formName].resetFields();
            // },
            handlePage(){
                this.axios.get("manage/reply/list",{params:{keyword:this.input}}).then(response=>{
                    if (response.data.code){
                        this.tableData = response.data.data;
                    }
                })
            },
            sortTable({prop, order}) {
                if (order === "ascending") {
                    this.tableData.sort((a, b) => this.sortName(a[prop], b[prop]));
                } else if (order === "descending") {
                    this.tableData.sort((a, b) => this.sortName(b[prop], a[prop]));
                } else {
                    this.tableData = [...this.tableDateCopy];
                }
            },
            sortName(a, b) {
                if (a < b) return -1;
                if (a > b) return 1;
                return 0;
            },
        }
    }
</script>

<style scoped>

</style>